package com.atguigu.spring.jdbc;

import com.atguigu.spring.jdbc.bean.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

/**
 * @author wk
 * @create 2021-06-03 15:37
 */
@ContextConfiguration(locations = "classpath:spring-jdbctemplate.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class JdbcTemplateTest {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Test
    public void testSelect(){
        String sql="select * from t_user";
        List<User> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(User.class));
        list.forEach(user -> System.out.println(user));
    }



}
